import { getAllRoleList, isAccountExist } from '/@/api/demo/system';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 80,
    ifShow: false,
  },
  {
    title: '姓名',
    dataIndex: 'psnName',
    width: 200,
    align: 'center',
    fixed: 'left',
  },
  {
    title: '工号',
    dataIndex: 'psnNum',
    width: 140,
    align: 'center',
  },
  {
    title: '部门名称',
    dataIndex: 'orgName',
    align: 'center',
    width: 140,
  },
  {
    title: '任职岗位',
    dataIndex: 'posName',
    width: 140,
    align: 'center',
  },
  {
    title: '人员类型',
    dataIndex: 'personType',
    width: 200,
    align: 'center',
    customRender: ({ text }) => {
      return render.renderDict(text, 'hub_person_type1');
    },
  },
  {
    title: '是否考核',
    dataIndex: 'isAssess',
    editRow: true,
    editComponent: 'Switch',
    width: 80,
    align: 'center',
  },
  {
    title: '不接受更新',
    dataIndex: 'notUpdate',
    editRow: true,
    editComponent: 'Switch',
    width: 110,
    align: 'center',
  },
  {
    title: '绩效兼职',
    dataIndex: 'epmPerson1Name',
    width: 140,
    align: 'center',
  },
  {
    title: '绩效经理',
    dataIndex: 'epmPerson2Name',
    width: 140,
    align: 'center',
  },
  {
    title: '绩效等级类型',
    dataIndex: 'perfLevelType',
    width: 200,
    align: 'center',
    customRender: ({ text }) => {
      return render.renderDict(text, 'hub_perf_level_type');
    },
  },
  {
    title: '绩效工资分配类型',
    dataIndex: 'prefSalaryType',
    width: 200,
    align: 'center',
    customRender: ({ text }) => {
      return render.renderDict(text, 'hub_pref_salary_type');
    },
  },
  {
    title: '绩效工资分配方式',
    dataIndex: 'prefSalaryWay',
    width: 200,
    align: 'center',
    customRender: ({ text }) => {
      return render.renderDict(text, 'hub_pref_salary_way');
    },
  },
  {
    title: '用工性质',
    dataIndex: 'userPosType',
    width: 200,
    align: 'center',
    customRender: ({ text }) => {
      return render.renderDict(text, 'epm_work_type');
    },
  },
  // {
  //   title: '是否主岗',
  //   dataIndex: 'mainpos',
  //   editRow: true,
  //   editComponent: 'Switch',
  //   width: 80,
  //   align: 'center',
  // },
  {
    title: '是否负责人',
    dataIndex: 'director',
    width: 120,
    align: 'center',
    editRow: true,
    editComponent: 'Switch',
  },
  {
    title: '排序',
    editRow: true,
    dataIndex: 'displayOrder',
    editComponent: 'InputNumber',
    align: 'center',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'psnName',
    label: '员工姓名',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'isAssess',
    label: '是否考核',
    component: 'Select',
    colProps: { span: 8 },
    componentProps: {
      options: [
        {
          label: '是',
          value: 'true',
        },
        {
          label: '否',
          value: 'false',
        },
      ],
    },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'account',
    label: '用户名',
    component: 'Input',
    helpMessage: ['本字段演示异步验证', '不能输入带有admin的用户名'],
    rules: [
      {
        required: true,
        message: '请输入用户名',
      },
      {
        validator(_, value) {
          return new Promise((resolve, reject) => {
            isAccountExist(value)
              .then(() => resolve())
              .catch((err) => {
                reject(err.message || '验证失败');
              });
          });
        },
      },
    ],
  },
  {
    field: 'pwd',
    label: '密码',
    component: 'InputPassword',
    required: true,
    ifShow: false,
  },
  {
    label: '角色',
    field: 'role',
    component: 'ApiSelect',
    componentProps: {
      api: getAllRoleList,
      labelField: 'roleName',
      valueField: 'roleValue',
    },
    required: true,
  },
  {
    field: 'dept',
    label: '所属部门',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'deptName',
        key: 'id',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    field: 'nickname',
    label: '昵称',
    component: 'Input',
    required: true,
  },

  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    required: true,
  },

  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
